﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DreamBuilder.DictionaryAccess;
using DreamBuilder.Core.DAO;


namespace DreamBuilder.UI.UserControls.DataAccess.Services
{
    public abstract class UCViewDAL : UserControlsDataAccessBase
    {
        abstract public string UCViewDBHelperString { get; set; }
        abstract public void GetChildTableData(ref System.Data.DataTable dtInfo, string childEditID, string parentKeyValue);
        abstract public DataTable GetEditData(System.Collections.Generic.List<VoucherEditItemInfo> pEditInfoList, string ID, string parentKey, VOUCHERTABLETYPE tableViewType);

        public IDataReader GetViewValueReader(string DisplayField, string TableCode, string PrimaryField, string fkValues)
        {
            string sSql = "select " + DisplayField + " from " + TableCode + " where " + PrimaryField + " in (" + fkValues + ")";
            if (!string.IsNullOrEmpty(UCViewDBHelperString))
            {
                IDBHelper dbHelper = DBHelperFactory.CreateInstance(UCViewDBHelperString);
                return dbHelper.ExecuteReader(sSql);
            }
            return null;
        }

        public DataSet GetViewTableNameAndID(string sql)
        {
            if (!string.IsNullOrEmpty(sql) && !string.IsNullOrEmpty(UCViewDBHelperString))
            {
                IDBHelper dbHelper = DBHelperFactory.CreateInstance(UCViewDBHelperString);
                return dbHelper.ExecuteDataSet(sql);
            }
            return null;
        }
    }
}
